package Exam;

import java.util.LinkedList;
import java.util.Queue;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Semaphore;
import java.util.concurrent.TimeUnit;

public class Park extends Thread {

    static Semaphore sp = new Semaphore(3);

    private Car c;

    public Park(Car c) {
        this.c = c;
    }

    //集合
    final Queue<Car> list = new LinkedList<Car>();


    @Override
    public void run() {
        try {
            sp.acquire();

            System.out.println(c.getName() + "正在停车");
            list.offer(c);
            TimeUnit.SECONDS.sleep(3);
        } catch (InterruptedException e) {
            e.printStackTrace();
        } finally {
            Car c2 = list.poll();
            System.out.println(c2.getName() + "出车位了");
            sp.release();
        }
    }

}
